package com.codeoss.framework.view.component;

import java.util.HashMap;
import java.util.Map;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.expression.Expression;

public abstract class Component {
	private Map<String,Object> attrMap=new HashMap<String,Object>();
	public abstract String getType();
	private String id;
	private Component parent;
	private Expression visibleExpression;
	private Expression onClickExpression;
	private Expression cssStyleExpression;
	private Expression cssClassExpression;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Component getParent() {
		return parent;
	}

	public void setParent(Component parent) {
		this.parent = parent;
	}

	public Expression getVisibleExpression() {
		return visibleExpression;
	}

	public void setVisibleExpression(Expression visibleExpression) {
		this.visibleExpression = visibleExpression;
	}

	public Expression getOnClickExpression() {
		return onClickExpression;
	}

	public void setOnClickExpression(Expression onClickExpression) {
		this.onClickExpression = onClickExpression;
	}

	public Expression getCssStyleExpression() {
		return cssStyleExpression;
	}

	public void setCssStyleExpression(Expression cssStyleExpression) {
		this.cssStyleExpression = cssStyleExpression;
	}

	public Expression getCssClassExpression() {
		return cssClassExpression;
	}

	public void setCssClassExpression(Expression cssClassExpression) {
		this.cssClassExpression = cssClassExpression;
	}

	public void setAttribute(String key,Object value) {
		attrMap.put(key, value);
	}
	
	public <T extends Object> T getAttribute(String key) {
		return (T)attrMap.get(key);
	}
	
	public Object removeAttribute(String key) {
		return attrMap.remove(key);
	}
	
	
	public void findComponentById(YunContext yunContext,String id) {
		if(id.equals(this.getId())) {
			yunContext.setFindComponent(this);
		}
	}
}
